home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / xlib / glxvis.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  4KB  |  98 lines

  1. /*
  2.  * Copyright (c) 1993-94, Silicon Graphics, Inc.
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that the name of Silicon Graphics may not be used in any advertising or
  7.  * publicity relating to the software without the specific, prior written
  8.  * permission of Silicon Graphics.
  9.  *
  10.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
  11.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  12.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  13.  *
  14.  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  15.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
  16.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE
  17.  * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN
  18.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  19.  *
  20.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  21.  */
  22. #include <GL/glx.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25.  
  26. static const char* ClassOf(int c)
  27. {
  28.     switch (c) {
  29.       case StaticGray:    return "StaticGray";
  30.       case GrayScale:    return "GrayScale";
  31.       case StaticColor:    return "StaticColor";
  32.       case PseudoColor:    return "PseudoColor";
  33.       case TrueColor:    return "TrueColor";
  34.       case DirectColor:    return "DirectColor";
  35.       default:        return "unknown";
  36.     }
  37. }
  38.  
  39. static void DumpGLXProperties(Display *dpy, XVisualInfo *vi)
  40. {
  41.     int bufferSize, level, rgba, doubleBuffer, stereo, auxBuffers,
  42.         redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize,
  43.         accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
  44.  
  45.     glXGetConfig(dpy, vi, GLX_BUFFER_SIZE, &bufferSize);
  46.     glXGetConfig(dpy, vi, GLX_LEVEL, &level);
  47.     glXGetConfig(dpy, vi, GLX_RGBA, &rgba);
  48.     glXGetConfig(dpy, vi, GLX_DOUBLEBUFFER, &doubleBuffer);
  49.     glXGetConfig(dpy, vi, GLX_STEREO, &stereo);
  50.     glXGetConfig(dpy, vi, GLX_AUX_BUFFERS, &auxBuffers);
  51.     glXGetConfig(dpy, vi, GLX_RED_SIZE, &redSize);
  52.     glXGetConfig(dpy, vi, GLX_GREEN_SIZE, &greenSize);
  53.     glXGetConfig(dpy, vi, GLX_BLUE_SIZE, &blueSize);
  54.     glXGetConfig(dpy, vi, GLX_ALPHA_SIZE, &alphaSize);
  55.     glXGetConfig(dpy, vi, GLX_DEPTH_SIZE, &depthSize);
  56.     glXGetConfig(dpy, vi, GLX_STENCIL_SIZE, &stencilSize);
  57.     glXGetConfig(dpy, vi, GLX_ACCUM_RED_SIZE, &accumRedSize);
  58.     glXGetConfig(dpy, vi, GLX_ACCUM_GREEN_SIZE, &accumGreenSize);
  59.     glXGetConfig(dpy, vi, GLX_ACCUM_BLUE_SIZE, &accumBlueSize);
  60.     glXGetConfig(dpy, vi, GLX_ACCUM_ALPHA_SIZE, &accumAlphaSize);
  61.  
  62.     printf("    bufferSize=%d level=%d rgba=%d doubleBuffer=%d stereo=%d\n",
  63.        bufferSize, level, rgba, doubleBuffer, stereo);
  64.     printf("    rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  65.        redSize, greenSize, blueSize, alphaSize);
  66.     printf("    auxBuffers=%d depthSize=%d stencilSize=%d\n",
  67.        auxBuffers, depthSize, stencilSize);
  68.     printf("    accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  69.        accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize);
  70. }
  71.  
  72. int main()
  73. {
  74.     XVisualInfo match, *vi;
  75.     Display *dpy;
  76.     int found;
  77.  
  78.     dpy = XOpenDisplay(0);
  79.     if (!dpy) {
  80.     fprintf(stderr, "Can't connect to display \"%s\"\n", getenv("DISPLAY"));
  81.     return -1;
  82.     }
  83.  
  84.     match.screen = DefaultScreen(dpy);
  85.     vi = XGetVisualInfo(dpy, VisualScreenMask, &match, &found);
  86.     while (--found >= 0) {
  87.     int value;
  88.     glXGetConfig(dpy, vi, GLX_USE_GL, &value);
  89.     if (value) {
  90.         printf("Visual ID: %x  depth=%2d  class=%s\n",
  91.            vi->visualid, vi->depth, ClassOf(vi->class));
  92.         DumpGLXProperties(dpy, vi);
  93.     }
  94.     vi++;
  95.     }
  96.     return 0;
  97. }
  98.